package svc

import (
	"charging_pile/common/sms"
	"charging_pile/devices/device"
	"charging_pile/models"
	"charging_pile/user/internal/config"

	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config    config.Config
	RedisObj  *redis.Redis
	Models    Models
	SmsClient sms.Client
	DeviceRpc device.Device
}

type Models struct {
	User   models.UserModel
	Wallet models.WalletModel
	Car    models.CarModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlconn := sqlx.NewMysql(c.DB.DataSource)
	return &ServiceContext{
		Config:   c,
		RedisObj: c.RedisConf.NewRedis(),
		Models: Models{
			User:   models.NewUserModel(sqlconn, c.Cache),
			Wallet: models.NewWalletModel(sqlconn, c.Cache),
		},
		SmsClient: sms.NewSmsTencentclient(c.Sms.Id, c.Sms.Key, c.Sms.AppId),
		DeviceRpc: device.NewDevice(zrpc.MustNewClient(c.DeviceRpcConf)),
	}
}
